package com.aspose.cells;

import java.util.ArrayList;
import java.util.HashMap;

class zanj {
   private int a;
   private int b;
   private byte[] c = null;
   private byte[] d = null;
   private Workbook e = null;
   private ArrayList f = new ArrayList();
   private ArrayList g = new ArrayList();
   private ArrayList h = new ArrayList();
   private ArrayList i = new ArrayList();
   private ArrayList j = new ArrayList();

   public zanj() {
      this.c = new byte[2];
      this.e = new Workbook();
      this.e.getWorksheets().clear();
      this.e.getWorksheets().q().a(0, 0);
   }

   public void a(String[] var1, String var2, String var3) throws Exception {
      com.aspose.cells.b.a.d.ze var4 = null;

      try {
         this.a(var1);
         var4 = this.b(var1, var2, var3);
         var4.a(0L, 0);
         com.aspose.cells.b.a.zg.a();
         com.aspose.cells.b.a.zg.b();
         zvh var5 = new zvh(WorksheetCollection.h);
         var5.a().a((Object)"Workbook", (Object)var4);
         var5.a(var3);
      } finally {
         if (var4 != null) {
            var4.a();
         }

         try {
            com.aspose.cells.b.a.d.zd.d(var2);
         } catch (Exception var11) {
            ;
         }

      }

   }

   private void a() {
      this.e.getWorksheets().o();
   }

   private com.aspose.cells.b.a.d.ze b(String[] var1, String var2, String var3) throws Exception {
      boolean var4 = zsu.a(this.e.getWorksheets());
      com.aspose.cells.b.a.d.ze var5 = com.aspose.cells.b.a.d.zd.a(var2);
      zqa var6 = new zqa(var5);
      if (var4) {
         this.a();
      }

      this.e.getWorksheets().p();
      com.aspose.cells.b.a.zg.a();
      com.aspose.cells.b.a.zg.b();
      zbwd var7 = new zbwd(this.e, new XlsSaveOptions());
      int[] var8 = new int[this.e.getWorksheets().getCount()];
      (new zbx(this.e, var7)).a(var6, var8);
      com.aspose.cells.b.a.zg.a();
      com.aspose.cells.b.a.zg.b();
      this.a(var1, var5, var3, var8);
      if (var4) {
         long var9 = var5.i();
         long var11 = (long)var8[var8.length - 1];
         var5.a(var11, 0);
         var5.b(com.aspose.cells.b.a.zc.a(var9), 0, 4);
         var5.a(var9, 0);
         Worksheet var13 = this.e.getWorksheets().get(this.e.getWorksheets().getCount() - 1);
         (new zbwq(var13, new zbwc(var7, this.e.getWorksheets().getCount() - 1))).a(var6);
      }

      return var5;
   }

   private void a(String[] var1) throws Exception {
      for(int var2 = 0; var2 < var1.length; ++var2) {
         com.aspose.cells.b.a.zg.a();
         com.aspose.cells.b.a.zg.b();
         Workbook var3 = new Workbook();
         zvh var4 = new zvh(var1[var2]);
         zbwo var5 = new zbwo(var3, (LoadOptions)null);
         com.aspose.cells.b.a.d.zh var6 = var4.a().a("Workbook");
         if (var6 == null) {
            var6 = var4.a().a("WORKBOOK");
            var4.a().g("WORKBOOK");
         } else {
            var4.a().g("Workbook");
         }

         zpb var7 = new zpb(var6);
         var3.getWorksheets().t();
         var5.b(var7);
         com.aspose.cells.b.a.a.ze.a(this.f, (Object)var6.i());
         var7 = null;
         var4 = null;
         var5 = null;
         var6.a();
         var6 = null;
         com.aspose.cells.b.a.zg.a();
         com.aspose.cells.b.a.zg.b();
         this.a(var3);
         if (var2 == 0) {
            this.e.getWorksheets().setActiveSheetIndex(var3.getWorksheets().getActiveSheetIndex());
         }

         var3 = null;
      }

   }

   private void a(Workbook var1) {
      int var2 = this.e.getWorksheets().getCount();
      int var3 = this.e.getWorksheets().getNames().getCount();
      HashMap var4 = new HashMap();
      com.aspose.cells.b.a.a.ze.a(this.j, (Object)var4);

      int var6;
      for(int var5 = 0; var5 < var1.getWorksheets().getCount(); ++var5) {
         if (this.e.getWorksheets().get(var1.getWorksheets().get(var5).getName()) != null) {
            this.e.getWorksheets().add();
         } else {
            this.e.getWorksheets().add(var1.getWorksheets().get(var5).getName());
         }

         var6 = var1.getWorksheets().q().f(var1.getWorksheets().u(), var5, var5);
         if (var6 != -1) {
            int var7 = this.e.getWorksheets().q().f(this.e.getWorksheets().u(), this.e.getWorksheets().getCount() - 1, this.e.getWorksheets().getCount() - 1);
            if (var4.get(var6) == null) {
               var4.put(var6, var7);
            }
         }
      }

      HashMap var15 = new HashMap();
      com.aspose.cells.b.a.a.ze.a(this.i, (Object)var15);

      int var9;
      Name var16;
      for(var6 = 0; var6 < var1.getWorksheets().getNames().getCount(); ++var6) {
         var16 = var1.getWorksheets().getNames().get(var6);
         Name var8 = new Name(this.e.getWorksheets());
         var8.a(var16);
         if (var16.getSheetIndex() == 0) {
            if (this.e.getWorksheets().getNames().get(var16.i()) != null) {
               var8.setSheetIndex(var16.o() + 1 + var2);
            }
         } else {
            var8.setSheetIndex(var16.getSheetIndex() + var2);
         }

         var9 = this.e.getWorksheets().getNames().a(var8, true);
         var15.put(var6, var9);
      }

      for(var6 = 0; var6 < var1.getWorksheets().getNames().getCount(); ++var6) {
         var16 = this.e.getWorksheets().getNames().get(var6 + var3);
         if (var16.b() != null) {
            zbwf.a(var16.b(), -1, -1, (HashMap)var4, (HashMap)var15);
         }
      }

      HashMap var17 = new HashMap();
      com.aspose.cells.b.a.a.ze.a(this.h, (Object)var17);
      HashMap var18 = new HashMap();

      for(int var19 = 0; var19 < var1.getWorksheets().z().size(); ++var19) {
         Font var21 = (Font)var1.getWorksheets().z().get(var19);
         int var10 = this.e.getWorksheets().b(var21);
         if (var19 < 4) {
            var18.put(var19, var10);
         } else {
            var18.put(var19 + 1, var10);
         }
      }

      zbvx var20 = var1.getWorksheets().B();

      int var11;
      for(var9 = var20.getCount() - 1; var9 > 15; --var9) {
         Style var23 = var20.a(var9);
         if (var23 != null && var23.c() == null) {
            var23.a((int)-1);
            var11 = this.e.getWorksheets().a(var23);
            var17.put(var9, var11);
         }
      }

      HashMap var22 = new HashMap();
      com.aspose.cells.b.a.a.ze.a(this.g, (Object)var22);
      zbpx var24 = var1.getWorksheets().g;

      for(var11 = 0; var11 < var24.a.length; ++var11) {
         zayy var12 = var24.a[var11];
         if (var12 != null) {
            if (var12.f()) {
               zbap var13 = (zbap)var12;
               int var14 = this.a(var13, var18);
               var22.put(var11, var14);
            } else {
               var12 = this.e.getWorksheets().g.a(var12.c);
               var22.put(var11, var12.e);
            }
         }
      }

   }

   private int a(zbap var1, HashMap var2) {
      byte[] var3 = var1.h();

      for(int var4 = 0; var4 < var3.length; var4 += 4) {
         int var5 = com.aspose.cells.b.a.zc.e(var3, var4 + 2) & '\uffff';
         Object var6 = var2.get(var5);
         if (var6 != null) {
            int var7 = (Integer)var6;
            if (var7 != var5) {
               System.arraycopy(com.aspose.cells.b.a.zc.a(var7), 0, var3, var4 + 2, 2);
            }
         }
      }

      return this.e.getWorksheets().g.a(var1.c, var3).e;
   }

   private void a(com.aspose.cells.b.a.d.zm var1, com.aspose.cells.b.a.d.zm var2) throws Exception {
      var1.a(this.c, 0, 2);
      this.b = (com.aspose.cells.b.a.zc.e(this.c, 0) & '\uffff') + 4;
      this.d = new byte[this.b];
      var1.a(-4L, 1);
      var1.a(this.d, 0, this.b);
      var2.b(this.d, 0, this.b);
   }

   private void a(com.aspose.cells.b.a.d.zm var1) throws Exception {
      var1.a(this.c, 0, 2);
      this.b = (com.aspose.cells.b.a.zc.e(this.c, 0) & '\uffff') + 4;
      this.d = new byte[this.b];
      var1.a(-4L, 1);
      var1.a(this.d, 0, this.b);
   }

   private void a(String[] var1, com.aspose.cells.b.a.d.zm var2, String var3, int[] var4) throws Exception {
      int var5 = 0;
      long var6 = 0L;
      int var8 = 0;
      long var9 = 0L;

      for(int var11 = 0; var11 < var1.length; ++var11) {
         zvh var12 = new zvh(var1[var11]);
         com.aspose.cells.b.a.d.zh var13 = var12.a().a("Workbook");
         if (var13 == null) {
            var13 = var12.a().a("WORKBOOK");
            var12.a().g("WORKBOOK");
         } else {
            var12.a().g("Workbook");
         }

         var12 = null;
         var13.a((Long)this.f.get(var11), 0);
         com.aspose.cells.b.a.zg.a();
         com.aspose.cells.b.a.zg.b();
         int var14 = 0;
         HashMap var15 = (HashMap)this.g.get(var11);
         HashMap var16 = (HashMap)this.h.get(var11);
         HashMap var17 = (HashMap)this.j.get(var11);
         HashMap var18 = (HashMap)this.i.get(var11);

         while(true) {
            while(var13.i() < var13.h()) {
               var13.a(this.c, 0, 2);
               this.a = com.aspose.cells.b.a.zc.e(this.c, 0) & '\uffff';
               int var20;
               byte[] var21;
               int var23;
               int var25;
               int var26;
               switch(this.a) {
               case 6:
               case 518:
                  this.a((com.aspose.cells.b.a.d.zm)var13);
                  var23 = com.aspose.cells.b.a.zc.e(this.d, 8) & '\uffff';
                  if (var23 != 15) {
                     var20 = (Integer)var16.get(var23);
                     System.arraycopy(com.aspose.cells.b.a.zc.a(var20), 0, this.d, 8, 2);
                  }

                  var20 = this.d.length - 24;
                  var21 = new byte[var20];
                  System.arraycopy(this.d, 24, var21, 0, var20);
                  zbwf.a(var21, -1, -1, (HashMap)var17, (HashMap)var18);
                  System.arraycopy(var21, 0, this.d, 24, var20);
                  var2.b(this.d, 0, this.d.length);
                  break;
               case 10:
                  --var14;
                  this.a((com.aspose.cells.b.a.d.zm)var13, (com.aspose.cells.b.a.d.zm)var2);
                  break;
               case 85:
                  if (var6 != 0L) {
                     var9 = var2.i();
                     var2.a(var6 + 16L, 0);
                     var2.b(com.aspose.cells.b.a.zc.a(var9), 0, 4);
                     var2.a(var9, 0);
                  }

                  this.a((com.aspose.cells.b.a.d.zm)var13, (com.aspose.cells.b.a.d.zm)var2);
                  break;
               case 176:
               case 236:
                  while(this.a != 574) {
                     var13.a(this.c, 0, 2);
                     this.b = com.aspose.cells.b.a.zc.e(this.c, 0) & '\uffff';
                     var13.a((long)this.b, 1);
                     var13.a(this.c, 0, 2);
                     this.a = com.aspose.cells.b.a.zc.e(this.c, 0) & '\uffff';
                  }

                  var13.a(-2L, 1);
                  break;
               case 189:
                  this.a((com.aspose.cells.b.a.d.zm)var13);
                  var23 = (com.aspose.cells.b.a.zc.e(this.d, this.d.length - 2) & '\uffff') - (com.aspose.cells.b.a.zc.e(this.d, 6) & '\uffff') + 1;

                  for(var20 = 0; var20 < var23; ++var20) {
                     var25 = com.aspose.cells.b.a.zc.e(this.d, 8 + 6 * var20) & '\uffff';
                     if (var25 != 15) {
                        var26 = (Integer)var16.get(var25);
                        System.arraycopy(com.aspose.cells.b.a.zc.a(var26), 0, this.d, 8 + 6 * var20, 2);
                     }
                  }

                  var2.b(this.d, 0, this.d.length);
                  break;
               case 190:
                  this.a((com.aspose.cells.b.a.d.zm)var13);
                  var23 = (com.aspose.cells.b.a.zc.e(this.d, this.d.length - 2) & '\uffff') - (com.aspose.cells.b.a.zc.e(this.d, 6) & '\uffff') + 1;

                  for(var20 = 0; var20 < var23; ++var20) {
                     var25 = com.aspose.cells.b.a.zc.e(this.d, 8 + 2 * var20) & '\uffff';
                     if (var25 != 15) {
                        var26 = (Integer)var16.get(var25);
                        System.arraycopy(com.aspose.cells.b.a.zc.a(var26), 0, this.d, 8 + 2 * var20, 2);
                     }
                  }

                  var2.b(this.d, 0, this.d.length);
                  break;
               case 215:
                  ++var8;
                  if (var6 != 0L) {
                     var9 = var2.i();
                     var2.a(var6 + 16L + (long)(4 * var8), 0);
                     var2.b(com.aspose.cells.b.a.zc.a(var9), 0, 4);
                     var2.a(var9, 0);
                  }

                  this.a((com.aspose.cells.b.a.d.zm)var13, (com.aspose.cells.b.a.d.zm)var2);
                  break;
               case 253:
                  this.a((com.aspose.cells.b.a.d.zm)var13);
                  var23 = com.aspose.cells.b.a.zc.e(this.d, 8) & '\uffff';
                  if (var23 != 15) {
                     var20 = (Integer)var16.get(var23);
                     System.arraycopy(com.aspose.cells.b.a.zc.a(var20), 0, this.d, 8, 2);
                  }

                  var20 = com.aspose.cells.b.a.zc.a(this.d, 10);
                  Object var24 = var15.get(var20);
                  boolean var22 = false;
                  if (var24 == null) {
                     var26 = 0;
                  } else {
                     var26 = (Integer)var24;
                  }

                  ++this.e.getWorksheets().g.a[var26].d;
                  System.arraycopy(com.aspose.cells.b.a.zc.a(var26), 0, this.d, 10, 4);
                  var2.b(this.d, 0, this.d.length);
                  break;
               case 513:
               case 515:
               case 516:
               case 517:
               case 638:
                  this.a((com.aspose.cells.b.a.d.zm)var13);
                  var23 = com.aspose.cells.b.a.zc.e(this.d, 8) & '\uffff';
                  if (var23 != 15) {
                     var20 = (Integer)var16.get(var23);
                     System.arraycopy(com.aspose.cells.b.a.zc.a(var20), 0, this.d, 8, 2);
                  }

                  var2.b(this.d, 0, this.d.length);
                  break;
               case 520:
                  this.a((com.aspose.cells.b.a.d.zm)var13);
                  if ((this.d[16] & 255 & 128) != 0) {
                     var23 = com.aspose.cells.b.a.zc.e(this.d, 18) & '\uffff' & 4095;
                     if (var23 != 15) {
                        var20 = (Integer)var16.get(var23);
                        var21 = com.aspose.cells.b.a.zc.a(var20);
                        var21[1] |= (byte)(this.d[19] & 255 & 240);
                        System.arraycopy(var21, 0, this.d, 18, 2);
                     }
                  }

                  var2.b(this.d, 0, this.d.length);
                  break;
               case 523:
                  var6 = var2.i();
                  this.a((com.aspose.cells.b.a.d.zm)var13, (com.aspose.cells.b.a.d.zm)var2);
                  break;
               case 574:
                  this.a((com.aspose.cells.b.a.d.zm)var13);
                  if (var5 - 1 == this.e.getWorksheets().getActiveSheetIndex()) {
                     this.d[5] = (byte)(this.d[5] | 6);
                  } else {
                     this.d[5] = (byte)(this.d[5] & 249);
                  }

                  var2.b(this.d, 0, this.d.length);
                  break;
               case 2057:
                  if (var14 == 0) {
                     var9 = var2.i();
                     long var19 = (long)var4[var5++];
                     var2.a(var19, 0);
                     var2.b(com.aspose.cells.b.a.zc.a(var9), 0, 4);
                     var2.a(var9, 0);
                     var8 = 0;
                  }

                  ++var14;
                  this.a((com.aspose.cells.b.a.d.zm)var13, (com.aspose.cells.b.a.d.zm)var2);
                  break;
               default:
                  this.a((com.aspose.cells.b.a.d.zm)var13, (com.aspose.cells.b.a.d.zm)var2);
               }
            }

            var2.b();
            var12 = null;
            var13.a();
            var13 = null;
            com.aspose.cells.b.a.zg.a();
            com.aspose.cells.b.a.zg.b();
            break;
         }
      }

   }
}
